package com.sun.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class DateUtil {

    public static String[] getWeekDates() {
        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai")); // 设置为中国时区
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(new Date());

        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        calendar.add(Calendar.DATE, -dayOfWeek + 2); // 本周一

        String[] dates = new String[7];
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < 7; i++) {
            Date date = calendar.getTime();
            dates[i] = dateFormat.format(date);
            calendar.add(Calendar.DATE, 1);
        }
        return dates;
    }

    public static String[] getThisYearMonths() {
        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai")); // 设置为中国时区
        calendar.setTime(new Date());

        String[] months = new String[12];
        SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM");
        for (int i = 0; i < 12; i++) {
            calendar.set(Calendar.MONTH, i);
            Date date = calendar.getTime();
            months[i] = monthFormat.format(date);
        }
        return months;
    }



}
